package utils

import (
	"encoding/json"
	"io/ioutil"
	"webdemo/src/zinx/zinterface"
)

type GlobalObject struct {
	TcpServer        zinterface.IServer
	Host             string
	TcpPort          int
	Name             string
	Version          string
	MaxConn          int
	MaxPackageSize   uint32
	WorkerPoolSize   uint32
	MaxWorkerTaskLen uint32
}

var GlobalObj *GlobalObject

func init() {
	GlobalObj = &GlobalObject{
		Name:             "ZinxServerApp",
		Version:          "v01",
		TcpPort:          8999,
		Host:             "0.0.0.0",
		MaxConn:          100,
		MaxPackageSize:   4096,
		WorkerPoolSize:   8,
		MaxWorkerTaskLen: 2048,
	}
	GlobalObj.Reload()
}

func (g *GlobalObject) Reload() {
	data, err := ioutil.ReadFile("src/zinxdemo/ZinxV1.0/conf/zinx.json")
	if err != nil {
		panic(err)
	}
	err = json.Unmarshal(data, &GlobalObj)
	if err != nil {
		panic(err)
	}
}
